﻿@model IEnumerable<KRM.Core.vPriceChangeHistory>
@{
    ViewBag.Title = "Price History";
    Layout = "~/Views/Shared/_PopupLayout.cshtml";
}
<script>
    function selectrowprice(date, productoptionid, price, productname, productoptiontext) {
        $("#hfaction").val("Edit");
        $("#price").val(price);
        $("#hfoldprice").val(price);
        $("#hfdate").val(date);
        $("#hfproductoptionid").val(productoptionid);
        $("#hfproductname").val(productname);
        $("#hfproductoptiontext").val(productoptiontext);
        $(".btn-viewaudit").attr("href", "/orderview/neworderpricehistoryaudit?productoptionid=" + productoptionid);
    }

    $(document).ready(function() {
        $("#fr-changepricehistory").submit(function() {
            if ($("#hfproductoptionid").val() == 0) {
                alert("Please select row");
                return false;
            }
            return true;
        });
        $(".btn-delete").click(function () {
                $("#hfaction").val("Delete");
                $(this).attr("type", "submit");
                $(this).trigger("click");
        });
    });
</script>
@Html.Partial("Partial/_MessageResult")
<div style="padding: 20px;">
    <form action="/orderview/NewOrderChangePriceHistory" method="POST" class="margin0" id="fr-changepricehistory">
        <input type="hidden" name="oldprice" id="hfoldprice"/>
        <input type="hidden" name="action" id="hfaction" value="Edit"/>
        <input type="hidden" name="date" id="hfdate"/>
        <input type="hidden" name="productoptionid" id="hfproductoptionid" value="0"/>
        <input type="hidden" name="productname" id="hfproductname"/>
        <input type="hidden" name="ProductOptionText" id="hfproductoptiontext"/>
        <div class="row-fluid">
            <div class="span1">Price</div>
            <div class="span2">
                <input type="text" name="newprice" id="price" class="input-block-level" />
            </div>
            <div class="span5">
                <input type="submit" value="Save" class="btn btn-primary" />
                <input type="button" value="Delete" class="btn btn-danger btn-delete" onclick="return confirm('Are you sure??')" />
                <a class="btn btn-success btn-viewaudit">View Audit</a>
            </div>
        </div>
    </form>
    <table class="table table-bordered table-fix tbl-selected">
        <thead>
            <tr>
                <th>DateX</th>
                <th>ProductOptionID</th>
                <th>ProductName</th>
                <th>ProductOptionText</th>
                <th>UserName</th>
                <th>Price</th>
                <th>RetailPriceExVAT</th>
                <th>DepartmentName</th>
                <th>ProductDisplay</th>
                <th>OptionDisplay</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model)
            {
                <tr onclick='selectrowprice("@(item.Date.ToString("yyyy-MM-dd HH:mm:ss.fff"))", @item.ProductOptionID, "@item.Price", "@item.ProductName", "@item.ProductOptionText")'>
                    <td>@item.Date</td>
                    <td>@item.ProductOptionID</td>
                    <td>@item.ProductName</td>
                    <td>@item.ProductOptionText</td>
                    <td>@item.UserName</td>
                    <td>@item.Price</td>
                    <td>@item.RetailPriceExVAT</td>
                    <td>@item.DepartmentName</td>
                    <td style="text-align: center">
                        <input type="checkbox" disabled="disabled" @(item.ProductDisplay ? "checked=checked" : "") /></td>
                    <td>@item.OptionDisplay</td>
                </tr>
            }
        </tbody>
    </table>
</div>

